home *** CD-ROM | disk | FTP | other *** search
-
- /* xlprint - xlisp print routine */
-
- #ifdef CI_86
- #include "a:stdio.h"
- #include "xlisp.h"
- #endif
-
- #ifdef AZTEC
- #include "a:stdio.h"
- #include "xlisp.h"
- #endif
-
- #ifdef unix
- #include <stdio.h>
- #include <xlisp.h>
- #endif
-
-
- /* external variables */
-
- extern struct node *xlstack;
-
-
- /* local variables */
-
- static struct node *printsym;
-
-
- /***********************************
- * print - builtin function print *
- ***********************************/
-
- static struct node *print(args)
- struct node *args;
- {
- xprint(args,TRUE);
- }
-
-
- /***********************************
- * princ - builtin function princ *
- ***********************************/
-
- static struct node *princ(args)
- struct node *args;
- {
- xprint(args,FALSE);
- }
-
-
- /***********************************
- * xprint - common print function *
- ***********************************/
-
- xprint(args,flag)
- struct node *args; int flag;
- {
- struct node *oldstk,arg,val;
-
- oldstk = xlsave(&arg,&val,NULL); /* New stack frame */
- arg.n_ptr = args;
-
- while (arg.n_ptr != NULL) /* Evaluate an print each arg */
- xlprint(xlevarg(&arg.n_ptr),flag);
-
- xlstack = oldstk; /* Restore old stack frame */
- return (NULL);
- }
-
-
- /***********************************
- * xlprint - print an xlisp value *
- ***********************************/
-
- xlprint(vptr,flag)
- struct node *vptr; int flag;
- {
- struct node *nptr,*next,*msg;
-
- #ifdef FGETNAME
- char buffer[128];
- #endif
-
- if (vptr == NULL) /* Print NULL as the empty list */
- {
- printf("()");
- return;
- }
-
- switch (vptr->n_type) /* Check value type */
- {
- case SUBR:
- printf("<Subr: #%o>",vptr);
- break;
-
- case LIST:
- putchar('(');
- for (nptr = vptr; nptr != NULL; nptr = next)
- {
- xlprint(nptr->n_listvalue,flag);
- if ((next = nptr->n_listnext) != NULL)
- if (next->n_type == LIST)
- putchar(' ');
- else
- {
- putchar('.');
- xlprint(next,flag);
- break;
- }
- }
- putchar(')');
- break;
-
- case SYM:
- printf("%s",vptr->n_symname);
- break;
-
- case INT:
- printf("%d",vptr->n_int);
- break;
-
- #ifdef REALS
- case REAL:
- printf("%g",vptr->n_real);
- break;
- #endif
-
- case STR:
- if (flag)
- putstring(vptr->n_str);
- else
- printf("%s",vptr->n_str);
- break;
-
- case FPTR:
-
- #ifdef FGETNAME
- printf("<File: %s>",fgetname(vptr->n_fp, buffer));
- #else
- printf("<File: #%o>",vptr);
- #endif
- break;
-
- case OBJ:
- if ((msg = xlmfind(vptr,printsym)) == NULL)
- xlfail("no print message");
- xlxsend(vptr,msg,NULL);
- break;
-
- case KMAP:
- printf("<Kmap: #%o>",vptr);
- break;
-
- default:
- printf("Invalid node type %d", vptr->n_type);
- break;
- }
- }
-
-
- /********************************
- * putstring - output a string *
- ********************************/
-
- static putstring(str)
- char *str;
- {
- int ch;
-
- putchar('"');
- while (ch = *str++)
- if (ch < 040 || ch == '\\') /* Check for control char */
- {
- putchar('\\');
- switch (ch)
- {
- case '\033':
- putchar('e');
- break;
-
- case '\n':
- putchar('n');
- break;
-
- case '\r':
- putchar('r');
- break;
-
- case '\t':
- putchar('t');
- break;
-
- case '\\':
- putchar('\\');
- break;
-
- default:
- printf("%03o",ch);
- break;
- }
- }
- else /* Output a normal char */
- putchar(ch);
-
- putchar('"');
- }
-
-
- /********************************************
- * xlpinit - initialize the print routines *
- ********************************************/
-
- xlpinit()
- {
- printsym = xlenter("print"); /* Find the print symbol */
-
- xlsubr("print",print); /* Enter the built in functions */
- xlsubr("princ",princ);
- }